using System;

namespace TSharp.Core.Util.TypeConvert
{
    /// <summary>
    /// 
    /// </summary>
    public class NullableGuidTypeDetectorImpl : NullableValueTypeDetector<Guid>
    {
        /// <summary>
        /// Byteses the specified byte16.
        /// </summary>
        /// <param name="byte16">The byte16.</param>
        /// <param name="TArg">The T arg.</param>
        /// <returns></returns>
        public override Guid? Bytes(byte[] byte16, Guid? TArg)
        {
            try
            {
                return new Guid(byte16);
            }
            catch
            {
                return TArg;
            }
        }

        /// <summary>
        /// Strings the specified detector obj.
        /// </summary>
        /// <param name="detectorObj">The detector obj.</param>
        /// <param name="arg">The arg.</param>
        /// <returns></returns>
        public override Guid? String(string detectorObj, Guid? arg)
        {
            try
            {
                return new Guid(detectorObj);
            }
            catch
            {
                return arg;
            }
        }

        /// <summary>
        /// GUIDs the specified detector obj.
        /// </summary>
        /// <param name="detectorObj">The detector obj.</param>
        /// <param name="arg">The arg.</param>
        /// <returns></returns>
        public override Guid? Guid(Guid detectorObj, Guid? arg)
        {
            return detectorObj;
        }
    }
}